package org.example;

import java.util.ArrayList;
import java.util.List;

public class Test2 {
    //leetcode 145 二叉树的后序遍历 https://leetcode.cn/problems/binary-tree-postorder-traversal/description/
    List<Integer> ret;
    public List<Integer> postorderTraversal(TreeNode root) {
        ret = new ArrayList<>();
        postOrder(root);
        return ret;
    }

    public void postOrder(TreeNode root) {
        if (root == null) return;
        postOrder(root.left);
        postOrder(root.right);
        ret.add(root.val);
    }
}
